var pid=0;
$(".news_pl").on("click",".commentbutton",function () {
    var _this=$(this);
$.get(isloginurl,function (ret) {
    if(ret==1) {
        var data = {
            "_token": csrf_token,
            "article_id": _this.data("articleid"),
            "pid": _this.data("pid"),
            "content": $.trim(_this.prev().val())
        }
        if (data.content == "") {
            alert("您没什么话要说吗？");
            $("#saytext").focus()
        }
        $.post(commenturl, data, function (ret) {
            if (ret) {
                console.log(ret)
                var temhtml = '<div class="fb">\n' +
                    '                            <ul class="fc">\n' +
                    '                                <li><img src="' + useravatar + '" /></li>\n' +
                    '                                <li class="fc_content">\n' +
                    '                                    <p class="fbtime">' + username + '</p>\n' +
                    '                                    <p class="fbinfo">' + ret.content + '</p>\n' +
                    '                                    <span class="timeandreply">' + ret.created_at + '&nbsp;&nbsp;&nbsp;<a href="javascript:;" data-pid="' + ret.id + '" class="reply">回复</a></span>\n' +
                    '                                </li>\n' +
                    '                            </ul>\n' +
                    '                        </div>';
                $(".gbko").prepend(temhtml)
                // window.location.reload()
            }
            console.log(ret.article_id)
        }
    )
    }else{
        $("#shade,#cloud").fadeIn(1000)
    }
})
})
$(".news_pl").on("click",".reply",function () {
    var _this=$(this)
    $.get(isloginurl,function (ret) {
        if(ret==1) {
            pid=_this.data("pid")
            $(".replymodal").remove()
            _this.closest(".fb").append('<div id="plpost" class="replymodal">\n' +
                '                            <textarea name="content" rows="6" class="content"></textarea>\n' +
                '                            <button class="replysubmit">提交</button>\n' +
                '                        </div>')

            $(".replysubmit").bind("click",function(){
                var _thissubmit=$(this)

                var data={
                    "_token":csrf_token,
                    "pid":pid,
                    "article_id":article_id,
                    "content":$.trim(_thissubmit.prev().val())
                }
                if(data.content==""){
                    alert("您没什么话要说吗？");
                }
                $.post(commenturl,data,function (ret) {
                    if(ret){
                        var tmphtml='<li class="fs">\n' +
                            '                                        <ul class="fc">\n' +
                            '                                            <li><img src="'+useravatar+'" /></li>\n' +
                            '                                            <li class="fc_content">\n' +
                            '                                                <p class="fbtime">'+username+'回复'+ret.reply_name+'</p>\n' +
                            '                                                <p class="fbinfo">'+ret.content+'</p>\n' +
                            '                                                <span class="timeandreply">'+ret.created_at+'&nbsp;&nbsp;&nbsp;<a href="javascript:;" data-pid="'+ret.id+'" class="reply">回复</a></span>\n' +
                            '                                            </li>\n' +
                            '\n' +
                            '                                        </ul>\n' +
                            '                                    </li>';

                        _this.closest(".fb").children(".fc").append(tmphtml)
                        // window.location.reload()
                        console.log(ret)
                        $(".replymodal").remove()
                    }
                })
            });
        }else{
            $("#shade,#cloud").fadeIn(1000)
        }
    })
})


